#include <cstdio>
#include <cstring>

struct Data
{
    char str[ 51 ];
    int v;
};

bool operator > ( Data a, Data b )
{
    return a.v > b.v;
}

void sort( Data stu[ ], int n )
{
    int i, j;
    Data t;
    for ( i = 0; i < n; i++ )
    {
        t = stu[ i ];
        for ( j = i; j > 0 && t > stu[ j - 1 ]; j-- )
            stu[ j ] = stu[ j - 1 ];
        stu[ j ] = t;
    }
}

int main( )
{
    int n, i, j,;
    Data stu[ 300 ];
    bool error, stable;
    char str[ 51 ];
    int v;
    while ( scanf("%d", &n) != EOF )
    {
        for ( i = 0; i < n; i++ )
            scanf("%s%d", stu[ i ].str, &stu[ i ].v);
        sort( stu, n );
        error = stable = false;
        for ( i = 0; i < n; i++ )
        {
            scanf("%s%d", str, &v);
            if ( v != stu[ i ].v )
                error = true;
            else
                if ( strcmp( stu[ i ].str, str ) != 0 )
                    stable = true;
        }
        if ( error )
        {
            printf("Error\n");
            for ( i = 0; i < n; i++ )
                printf("%s %d\n", stu[ i ].str, stu[ i ].v);
        }
        else
            if ( stable )
            {
                printf("Not Stable\n");
                for ( i = 0; i < n; i++ )
                    printf("%s %d\n", stu[ i ].str, stu[ i ].v);
            }
            else
                printf("Right\n");
    }    
    return 0;
}
